'''
Created on Dec 5, 2009

@author: tliu
'''
from google.appengine.ext import db
 

def createEntry(author, title, type, content):
    entry = Entry(author = author,
                  title = title,
                  type = type,
                  content = content)
    entry.comments = []
    entry.put()
    return entry
    
class Entry(db.Model):
    from User import User
    date = db.DateTimeProperty(auto_now=True)
    author = db.ReferenceProperty(User, required=True)
    type = db.StringProperty(required=True, choices=set(["question", "idea"]))
    title = db.StringProperty(required=True)
    content = db.TextProperty(required=True)
    comments = db.ListProperty(db.Key)
    
    def updateType(self, new_type):
        self.type = new_type
        self.put()
        
    def updateContent(self, content):
        self.content = content
        self.put()
        
    def addComment(self, comment):
        from Comment import Comment
        self.comments.append(comment.key())
        self.put()
        
    def getComments(self):
        from Comment import Comment
        return map(lambda x:Comment.get(x), self.comments)
    
    
    
